home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / ARPDUMP.C < prev    next >
C/C++ Source or Header  |  1989-07-21  |  2KB  |  82 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "timer.h"
  5. #include "arp.h"
  6. #include "ax25.h"
  7. #include "netuser.h"
  8.  
  9. extern FILE *trfp;
  10.  
  11. arp_dump(bpp)
  12. struct mbuf **bpp;
  13. {
  14.     struct arp arp;
  15.     struct arp_type *at;
  16.     int is_ip = 0;
  17.     char buf[128];
  18.  
  19.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  20.         return;
  21.     fprintf(trfp,"ARP: len %d",len_mbuf(*bpp));
  22.     if(ntoharp(&arp,bpp) == -1){
  23.         fprintf(trfp," bad packet\n");
  24.         return;
  25.     }
  26.     /* Print hardware type in Ascii if known, numerically if not */
  27.     if(arp.hardware < NHWTYPES){
  28.         at = &arp_type[arp.hardware];
  29.         fprintf(trfp," %s",arptypes[arp.hardware]);
  30.     } else {
  31.         at = NULLATYPE;
  32.         fprintf(trfp," hwtype %u",arp.hardware);
  33.     }
  34.     /* Print hardware length only if unknown type, or if it doesn't match
  35.      * the length in the known types table
  36.      */
  37.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  38.         fprintf(trfp," hwlen %u",arp.hwalen);
  39.  
  40.     /* Check for most common case -- upper level protocol is IP */
  41.     if(at != NULLATYPE && arp.protocol == at->iptype){
  42.         fprintf(trfp," IP");
  43.         is_ip = 1;
  44.     } else {
  45.         fprintf(trfp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  46.     }
  47.     switch(arp.opcode){
  48.     case ARP_REQUEST:
  49.         fprintf(trfp," REQUEST");
  50.         break;
  51.     case ARP_REPLY:
  52.         fprintf(trfp," REPLY");
  53.         break;
  54.     default:
  55.         fprintf(trfp," op %u",arp.opcode);
  56.         break;
  57.     }
  58.     /* dump source and target protocol and hardware addresses */
  59.     if(is_ip)
  60.         fprintf(trfp," [%s]",inet_ntoa(arp.sprotaddr));
  61.     if(at != NULLATYPE && at->format != NULLFP){
  62.         /* for AX.25 type, mark end of address for format func */
  63.         if(arp.hardware == ARP_AX25)
  64.             arp.shwaddr[uchar(arp.hwalen)-1] |= E;
  65.         (*at->format)(buf,arp.shwaddr);
  66.         fprintf(trfp," %s",buf);
  67.     }
  68.     fprintf(trfp,"->");
  69.     if(is_ip)
  70.         fprintf(trfp,"[%s] ",inet_ntoa(arp.tprotaddr));
  71.     if(at != NULLATYPE && at->format != NULLFP){
  72.         /* for AX.25 type, mark end of address for format func */
  73.         if(arp.hardware == ARP_AX25)
  74.             arp.thwaddr[uchar(arp.hwalen)-1] |= E;
  75.         (*at->format)(buf,arp.thwaddr);
  76.         if(!buf[0] || buf[0] == '?')
  77.             strcpy(buf,"unknown");
  78.         fprintf(trfp,"%s",buf);
  79.     }
  80.     fprintf(trfp,"\n");
  81. }
  82.